package BehavioralPatterns.Command;

/*
遥控器
 */
public class RemoteController {

//  按钮的命令
  Command [] onCommands;
  Command [] offCommands;

//  撤销的命令
  Command undoCommands;
  
  public RemoteController(){
    onCommands = new Command[5];
    offCommands = new Command[5];

    for (int i = 0; i < 5; i++) {
      onCommands[i] = new NoCommand();
      offCommands[i] = new NoCommand();
    }
  }
//   设置命令
  public void setCommands(int no,Command onCommand,Command offCommand){
    onCommands[no] = onCommand;
    offCommands[no] = offCommand;
  }

//  按下开按钮
  public void onButtonWasPush(int no){
    onCommands[no].excute();
//    记录撤销的按钮
    undoCommands = onCommands[no];
  }

//  按下关按钮
  public void offButtonWasPush(int no){
    offCommands[no].excute();
    undoCommands = offCommands[no];
  }

//  按下撤销按钮
  public void undoButtonWasPush(){
    undoCommands.undo();
  }
}
